package cn.tedu;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.*;

import java.io.IOException;

public class MusicReducer extends TableReducer<Text, IntWritable, Text> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        //播放次数
        int playCount = 0;
        for (IntWritable intWritable : values) {
            playCount += intWritable.get();
        }
        //为put操作指定行键
        Put put = new Put(Bytes.toBytes(key.toString()));
        //为put操作指定列和值
        put.addColumn(Bytes.toBytes("details"), Bytes.toBytes("rank"), Bytes.toBytes(playCount));
        context.write(key, put);
    }
}
